package org.rambadger.command.view;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import com.fasterxml.jackson.annotation.JsonValue;
import com.yammer.dropwizard.auth.Auth;
import com.yammer.dropwizard.views.View;
import org.rambadger.command.auth.AuthUser;
import org.rambadger.command.representation.Platform;

import java.util.ArrayList;
import java.util.List;

public class PlatformsView extends View {
    public List<PlatformView> platforms;

    String title = ": Platforms";
    boolean area_platforms = true;      //boolean for check active in navbar
    //pagjnation variables
    boolean pagj,pagj_front,pagj_back = false;
    int pagj_less,pagj_great,pagj_limit,pagj_end;
    ArrayList<pagj> pagjnation;
    boolean hasAdmin = false;

    public PlatformsView(@Auth(required = false) AuthUser user, List<PlatformView> platforms) {
        super("/platformsList.mustache");
        this.platforms = platforms;
        if (user!=null)
        this.hasAdmin = user.hasAdmin();
    }

    public PlatformsView(@Auth(required = false) AuthUser user, List<PlatformView> platforms, int pagesTotal, int platformsPerPage, int currentPage) {
        super("/platformsList.mustache");
        this.platforms = platforms;
        if (user!=null)
        this.hasAdmin = user.hasAdmin();
        this.pagj = true;
        if (currentPage == 1)
            this.pagj_front = true;
        if (currentPage == pagesTotal)
            this.pagj_back = true;
        pagjnation = new ArrayList<>();
        for (int i=1;i<=pagesTotal;i++){
            if (i == currentPage)
                this.pagjnation.add(new pagj(i, false));
            else
                this.pagjnation.add(new pagj(i, true));
        }
        this.pagj_less = currentPage - 1;
        this.pagj_great = currentPage + 1;
        this.pagj_limit = platformsPerPage;
        this.pagj_end = pagesTotal;
    }

    @JsonValue
    public List<PlatformView> getPlatforms() {
        return platforms;
    }
}

class pagj {
    int page;
    boolean active;

    public pagj(int page, boolean active) {
        this.page = page;
        this.active = active;
    }
}
